package com.yuwubao.uav.tool.service.impl;

import com.yuwubao.framework.bean.PageData;
import com.yuwubao.uav.tool.mapper.LearningMaterialsMapper;
import com.yuwubao.uav.tool.service.LearningMaterialsService;
import com.yuwubao.uav.tool.util.StringUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 */
@Service
public class LearningMaterialsServiceImpl implements LearningMaterialsService {

    private static final Logger logger = LogManager.getLogger(LearningMaterialsServiceImpl.class.getName());

    @Resource
    private LearningMaterialsMapper learningMaterialsMapper;

    @Override
    public void deleteLearningMaterials(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    learningMaterialsMapper.deleteLearningMaterials(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updateLearningMaterials(PageData pageData) throws Exception {
        try{
            learningMaterialsMapper.updateLearningMaterials(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void disableOrEnableLearningMaterials(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    learningMaterialsMapper.disableOrEnableLearningMaterials(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void addLearningMaterials(PageData pageData) throws Exception {
        try{
            learningMaterialsMapper.addLearningMaterials(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public List<PageData> listLearningMaterials(PageData pageData) throws Exception {
        try{
            return learningMaterialsMapper.listLearningMaterials(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public int listLearningMaterialsCount(PageData pageData) throws Exception {
        try{
            return learningMaterialsMapper.listLearningMaterialsCount(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }

}
